﻿attend_report_fake_data=[
    {	empid:'AE1856',name:'何宇林',personal_leave:'17',sick_leave:'3',annual_leave:'2',paid_leave:'2',swap_off:'2.5',late1:'1',late2:'2',late3:'1',late4:'1',full:true,absent:'12',deduction:'2',late_team:'12:20',late_person:'12:45',overtime:'12:30'},
    {empid:'AE1857',name:'白联军',personal_leave:'17',sick_leave:'3',annual_leave:'2',paid_leave:'2',swap_off:'2.5',late1:'1',late2:'2',late3:'1',late4:'1',full:true,absent:'12',deduction:'2',late_team:'12:20',late_person:'12:45',overtime:'12:30'},
       ]

app.controller('attend_report_controller',function  ($scope,$http,headFilterManager) {
	$scope.fb={
		show:{
			keywords:true,
		},
	}
	$scope.heads=[	{name:'empid',label:'员工号',filter:true},
					{name:'name',label:'姓名',filter:true},
					{name:'start_date',label:'统计开始',filter:true},
					{name:'due_date',label:'统计截止'},
					{name:'personal_leave',label:'事假',},
					{name:'sick_leave',label:'病假',},
					{name:'annual_leave',label:'年假',},
					{name:'paid_leave',label:'带薪假',},
					{name:'swap_off',label:'调休',},
					{name:'late1',label:'迟到1'},
					{name:'late2',label:'迟到2'},
					{name:'late3',label:'迟到3'},
					{name:'late4',label:'迟到4'},
					{name:'full_attend',label:'全勤'},
					{name:'absent',label:'旷工'},
					{name:'deduction',label:'扣款'},
					{name:'late_team',label:'团队迟到时间'},
					{name:'late_person',label:'个人迟到时间'},
					{name:'overtime',label:'加班'},
					];
	
	$scope.currentPage =0;
	$scope.itemsPerPage =20;
	if(is_local){
        $scope.org_reports=attend_report_fake_data
	}else{
		$scope.org_reports=[]
	}
	$scope.reports=$scope.org_reports

	// -----------为了头部过滤------------
	var hfmanagr=new headFilterManager.HFManager()
	hfmanagr.initHeads($scope.heads)
	$scope.$on('head_filter_changed',function (even,filter) {
		if(hfmanagr.has_filter(filter)){
			//$scope.records=$scope.funlist_filter($scope.org_records)
			$scope.reports=hfmanagr.filter($scope.org_reports)
		}
	})
	//-某个头部排序，通知其他排序变为'不排序'
	$scope.$on('sortClick',function (even,name) {
		$scope.$broadcast('otherSortClick',name);
	})
	//---
	$scope.search=function (start_date,end_date,fb) {
		var leave=$scope.leave;
		var post_data = {
				hr_attend_report:{	start_date:start_date,
									due_date:end_date,keyword:fb.keywords},
			};  
		$scope.fb.uploading=true;
		$http.post(post_url,post_data)
		.success(function(data, status, headers, config) { 
			$scope.org_reports=data.hr_attend_report.reports;
			$scope.reports=$scope.org_reports
			$scope.currentPage=0;
			$scope.fb.uploading=false;
		}).error(function(data, status, headers, config) {  
		    alert('有错误,返回码为:'+status)
		    $scope.fb.uploading=false;
		});
		}
})


